import { createRouter, createWebHistory } from 'vue-router'
import AdminLayout from '@/layout/admin/index.vue'
import FrontLayout from '@/layout/front/index.vue'

const routes = [
  {
    path: '/',
    redirect: '/home',
    component: FrontLayout,
    name: 'FrontLayout',
    children: [
      {
        path: 'home',
        component: () => import('@/views/front/home/index.vue'),
        name: 'Home',
      },
      {
        path: 'about',
        component: () => import('@/views/front/about/index.vue'),
        name: 'About',
      },
      {
        path: 'article-preview/:id',
        component: () => import('@/views/front/article-preview/index.vue'),
        name: 'ArticlePreview',
      },
    ],
  },
  {
    path: '/admin-login',
    component: () => import('@/views/admin/login/index.vue'),
    name: 'AdminLogin',
  },
  {
    path: '/admin-layout',
    redirect: '/admin-layout/dashboard',
    component: AdminLayout,
    name: 'AdminLayout',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/admin/dashboard/index.vue'),
        name: 'Dashboard',
      },
      {
        path: 'article',
        component: () => import('@/views/admin/article/index.vue'),
        name: 'Article',
      },
      {
        // 使 id 可选，这样同一个路由既能用于创建也能用于编辑
        path: 'article-edit/:id?',
        component: () => import('@/views/admin/article/ArticleEdit.vue'),
        name: 'ArticleEdit',
      },
      {
        path: 'category',
        component: () => import('@/views/admin/category/index.vue'),
        name: 'Category',
      },
      {
        path: 'tag',
        component: () => import('@/views/admin/tag/index.vue'),
        name: 'Tag',
      },
      {
        path: 'image',
        component: () => import('@/views/admin/image/index.vue'),
        name: 'Image',
      },
      {
        path: 'account',
        component: () => import('@/views/admin/account/index.vue'),
        name: 'Account',
      },
    ],
  },
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

export default router
